<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>解放军第三〇五医院</title>
    <!-- css部分-->
    <link href="${basePath}/static/css/Common/basic.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/Pigeonhole/Pigeonhole_info.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="${basePath}/static/publics/assets/swiper/css/swiper.min.css"/>
</head>
<body>
<div id="file_container" class="clearfix">
    <div class="files_title">
        <h3>病案绑定 &gt; 选择患者</h3>
        <ul>
            <!--<li><a>保存</a></li>-->
            <li><a id="closeBtn" onclick="custom_close()">关闭</a></li>
        </ul>
    </div>

    <div class="file_content">
        <div class="file_header">
            <div class="left">文件信息</div><div class="right">当前页码 <span id="swipePage">1</span>/<span id="totalPage">${urlCount}</span></div>
        </div>
        
   
        <div class="files">
            <div class="swiper-container swiper-container-horizontal">
                <div class="swiper-wrapper">
                	<c:forEach items="${urlList}" var="url"  varStatus="xh">
                	<c:choose>
                	<c:when test="${url.fileType=='pdf'}">
                     <div class="swiper-slide" data-index="${xh.index +1}">
                        <iframe width="100%" height="100%" src="${hospitalizationNoteResourceUrl}${url.fileUrl}${url.fileName}"></iframe>
                   	 </div>
                    </c:when>
                    <c:otherwise>
	                    <div class="swiper-slide" data-index="${xh.index +1}">
	                        <img src="${hospitalizationNoteResourceUrl}${url.fileUrl}${url.fileName}" alt="">
	                    </div>
                    </c:otherwise>
               		</c:choose>
                    </c:forEach>
                </div>
                <!-- Add Pagination -->
                <!--<div class="swiper-pagination"></div>-->
                <!-- Add Arrows -->
                <div class="swiper-button-next"></div>
                <div class="swiper-button-prev"></div>
            </div>
        </div>
    </div>
    <div class="file_con_table">
   
        <div class="search_table">
            <ul>
                <li class="Label_1" id="username">姓名：&nbsp;</li>
                <li class="Label_2"><input class="input_box" type="text" maxlength="15" name="" id="name" value=""></li>
                <li class="Label_1">身份证：&nbsp;</li>
                <li class="Label_2"><input class="input_box" maxlength="18" type="text" name="" id="idNumber" value=""></li>
                <li class="Label_5">
                    <a class="btn" href="${basePath}/bind/addPatientPage?id=${uploadScanId}">新增</a>
                    <input class="btn" type="button"  value="查询" onclick="getPatientMsg()"/>
                </li>
            </ul>
        </div>
        <div class="searchList">
            <!-- <div class="searchList_title">
                &nbsp;&nbsp; <b class="patientName"></b>&nbsp;&nbsp;<b class="patientCard"></b>&nbsp;&nbsp;<b class="sex"></b>
                <button onclick="addMedicalPage()"  class="right">新增诊疗记录</button>
            </div>
            <table cellpadding="0" cellspacing="0">
                
                <tr>
                    <td class="tdLabel_4">识别码</td>
                    <td class="tdLabel_4">入院时间</td>
                    <td class="tdLabel_4">所属医院</td>
                    <td class="tdLabel_4">出院科室</td>
                    <td class="tdLabel_4">操作</td>
                   
                </tr>
              <tbody id="tbody">
                
            
                </tbody></table> -->
        </div>
    </div>
</div>
<!--JS部分-->
<script type="text/javascript" src="${basePath}/static/publics/assets/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/swiper/js/swiper.min.js"></script>
<script type="text/javascript" src="${basePath}/static/js/swiper.js"></script>
<script type="text/javascript" src="${basePath}/static/js/util.js"></script>
<script>
	//根据用户名和身份证号查询患者信息
	function getPatientMsg(){
		$(".input_box").focus(function(){
			$(".input_box").removeClass("input_changeCss");
		});
		var name=$("#name").val();
		var idNumber=$("#idNumber").val();
		if((name==null || name=="")&& (idNumber==null || idNumber=="")){
			alert("请至少输入一条查询条件!");
			$(".input_box").addClass("input_changeCss");
			return;
		} 
		
		//校验姓名
		if(name!=null && name!=""){
			if(checkChinese(name)==false){
				alert("姓名输入格式不正确!");
				$("#name").addClass("input_changeCss");
				return;
			}
		}
		
		//校验身份证
		if(idNumber!=null && idNumber!=""){
			var flag=validateIdCard(idNumber);
		 	if(flag==false){
		 		$("#idNumber").addClass("input_changeCss");
				return;
		 	}
		}
		
		$.ajax({
			type:"post",
			url:"${basePath}/bind/getPatientMsg",
			data:{name:name,idNumber:idNumber},
			success:function(data){
				
				if(data.success==false){
					alert(data.msg);
					return;
				}
				
				if(data.success=true){
					if(data.data==null){
						alert(data.msg);
						$("#tbody").html("");
						return;
					}
					
			
					var objs=data.data;
					var html="";
					for(var i in objs){
						var citizen=objs[i];
						html+="<div class='searchList_title'>"+
		               " &nbsp;&nbsp; <b>"+citizen.name+"</b>&nbsp;&nbsp;<b>"+citizen.idNumber+"</b>&nbsp;&nbsp;<b>"+citizen.sex+"</b>"+
		                "<button  guid='"+citizen.guid+"' onclick='addMedicalPage(this)'  class='right'>新增诊疗记录</button>"+
		           " </div>";
		           
		           html+=" <table cellpadding='0' cellspacing='0'>"+ 
	               " <tr>"+
	                   " <td class='tdLabel_4'>识别码</td>"+
	                   " <td class='tdLabel_4'>入院时间</td>"+
	                   " <td class='tdLabel_4'>所属医院</td>"+
	                   " <td class='tdLabel_4'>出院科室</td>"+
	                   "<td class='tdLabel_4'>操作</td>"+  
	                "</tr>";
	                
	                var patientMsgList=citizen.patientMsgList;
	                
	                for(var index in patientMsgList){
	                	var obj=patientMsgList[index];
	                	html+="<tr>"+
	                    "<td class='tdLabel_5'>"+obj.mrId+"</td>"+
	                    "<td class='tdLabel_5'>"+obj.inHospitalDate+"</td>"+
	                    "<td class='tdLabel_5'>"+obj.hospitalName+"</td>"+
	                    "<td class='tdLabel_5'>"+obj.officeName+"</td>"+
	                    "<td class='tdLabel_5'><a guid='"+obj.guid+"' onclick='bindUrl(this)'>绑定</a></td>"+
	                "</tr>"; 
	                }
	                
	                html+="</table>";
					}
					$(".searchList").html(html);
				}
			}
			
			
		});	
	}
	
	//将url和诊疗记录进行关联
	function bindUrl(obj){
		//扫描信息
		var uploadScanId=window.location.search.split("=")[1];
		var $this=$(obj);
		var guid=$this.attr("guid");
		
		$.ajax({
			type:"post",
			url:"${basePath}/bind/bindUrl",
			data:{guid:guid,uploadScanId:uploadScanId},
			success:function(data){
				if(data.success==false){
					alert(data.msg);
					return;
				}
				alert(data.msg);
				$this.closest("tr").remove();
				
			}
		});
	}
	
	
	//跳转到添加病案信息页面
	function addMedicalPage(obj){
		var $this=$(obj);
		//扫描信息
		var uploadScanId=window.location.search.split("=")[1];
		var citizenGuid=$this.attr("guid");
		//alert(uploadScanId+"--"+citizenGuid);
		window.location.href="${basePath}/bind/addMedicalPage?uploadScanId="+uploadScanId+"&citizenGuid="+citizenGuid;
	}
</script>
</body>
</html>